<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <div th:replace="template :: head-common"></div>
    <style>
        .to-login {
            width: 50%;
            margin-top: 15%;
            margin-left: 38%;

        }

        .login-form {
            width: 40%;
            color: #b9bbbe;
        }
    </style>
</head>
<body style="background-color: #0c5b60">
<div class="to-login">
    <form action="" class="login-form">

        <div class="form-group">
            <label for="username">用户名：</label>
            <input type="text" class="form-control" name="username" placeholder="用户名">
            <input type="hidden" class="form-control" name="grant_type" value="password">
        </div>
        <div class="form-group">
            <label for="password">密码：</label>
            <input type="password" class="form-control" name="password" placeholder="密码">
        </div>
    </form>
    <div class="form-group">
        <button class="btn btn-success btn-lg btn-login">登录</button>
    </div>
</div>
</body>
<script>
    var $form = $(".login-form");
    var $username = $("input[name='username']");
    var $password = $("input[name='password']");
    $(function () {
        $(".btn-login").click(function () {
            if (!$username.val()) {
                alert("用户名不能为空");
                return;
            }
            if (!$password.val()) {
                alert("密码不能为空");
                return;
            }
            var data = $form.serialize();
            $.ajax({
                url: "/oauth/token",
                type: "post",
                data: data,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('Authorization', make_base_auth("app_client", "app_secret"));
                },
                success: function (resp) {
                    storeToken(resp);
                    window.location.href="/";
                },
                error: function (resp) {

                }
            })
        });
    })

</script>
</html>